package com.example.article.core.page.response;

import com.example.article.core.Constant;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;

@Builder
@Data
public class APIResponse<R> {

    //含有泛型的方法
    public static <R> APIResponse<R> makeSuccess(R data) {

        return APIResponse.<R>builder()
                .code(Constant.SUCCESS)
                .data(data)
                .build();
    }

    public static <R> APIResponse<R> makeMessage(String meg) {

        return APIResponse.<R>builder()
                .code(Constant.SUCCESS)
                .message(meg)
                .build();
    }

    private Integer code;
    private R data;
    private String message;

    @Tolerate //实现解决和Builder冲突的构造方法
    public APIResponse() {
    }
}
